package com.fanfutian.eventproject.mapper;


import com.fanfutian.eventproject.pojo.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {


    /**
     * 新增文章
     * @param article
     */
    @Insert("insert into db_event_project.article(title, content, cover_img, state, category_id, create_user, create_time, update_time) " +
            "values(#{title}, #{content}, #{coverImg}, #{state}, #{categoryId}, #{createUser}, #{createTime}, #{updateTime})")
    void addArticle(Article article);


    /**
     * 查询文章列表
     * @param categoryId
     * @param state
     * @param userId
     * @return
     */
    List<Article> list(Integer categoryId, String state, Integer userId);


    /**
     * 查询文章详情
     * @param id
     * @param userId
     * @return
     */
    @Select("select * from db_event_project.article where id = #{id} and create_user = #{userId}")
    Article detail(Integer id, Integer userId);


    /**
     * 修改文章信息
     * @param article
     */
    @Update("update db_event_project.article set title=#{title}, content=#{content}, cover_img=#{coverImg}," +
            "state=#{state}, category_id=#{categoryId}, update_time=#{updateTime} where create_user=#{createUser} and id=#{id}")
    void updateArticle(Article article);


    /**
     * 删除文章信息
     * @param id
     * @param userId
     */
    @Delete("delete from db_event_project.article where id = #{id} and create_user = #{userId}")
    void deleteArticle(Integer id, Integer userId);
}
